<?	
    session_start();
    include('conn.php');	
    include('protect.php');	
    include('gettopmenu.php');	
   	   
    $sd=date("d-m-Y");
    $_SESSION['custid']=0;	
    $_SESSION['custtype']='0';
  
    if(isset($_REQUEST['custid']))
    {	
		//$_REQUEST['custid'] = 194-abc@xyz.com
		$custinfo = explode("-", $_REQUEST['custid']);
        $_SESSION['custid']=$custinfo[0];
    }
    else
    {	
        $_SESSION['custid']=0;	
    }	
  
    
	if(isset($_REQUEST['custtype']))	
	{
	$_SESSION['custtype']=$_REQUEST['custtype'];
	}
	else
	{	
		$_SESSION['custtype']="0";	
	}	
        
	 if(isset($_REQUEST['startdate']))	
	 {
	 $_SESSION['startdate']=$_REQUEST['startdate'];
	}
    else
	{	
		 $_SESSION['startdate']=date("Y-m-d");	
    }	

		$msg='';
  ?>
            
            
    <script type="text/javascript" src="outstandingmain.js"></script>
    <script language="javascript"> 
        $(function() 
        {
            $("#startdate").datepicker({ dateFormat: "dd-mm-yy" }).val()			   
        }
         
       );

	function ShowInvoice()
     {
	      var s=document.outst.startdate.value; 
		  var custidandemail = document.outst.custid.value.split('-');
		   
		   var c=custidandemail[0];
		   var email = custidandemail[1];
		   var custdesc=document.outst.custid.text;
		   var cd = document.outst.custid.options[document.outst.custid.selectedIndex].text;
		   var s2='<?=date("d-m-Y")?>';
		   var client='Shree Communications';
		   var link = 'report_invoice.php?custid='+c+'&custdesc='+cd+'&date='+s2+'&clientname='+client+'&startdate='+s;
		   //alert(link);
			window.open(link,'_blank');
	
	   }
	   
        function ShowStatement()
       {
	      var s=document.outst.startdate.value; 
		  var custidandemail = document.outst.custid.value.split('-');
		   
		   var c=custidandemail[0];
		   var email = custidandemail[1];
		   var custdesc=document.outst.custid.text;
		   var cd = document.outst.custid.options[document.outst.custid.selectedIndex].text;
		   var s2='<?=date("d-m-Y")?>';
		   var client='Shree Communications';
		   // new code
		   // var emailto='mail@firstnorthglobal.com';
			var emailcc='manish@shreecomm.com'; // put another address
			
		   var link = 'report_ledger_bydate.php?custid='+c+'&custdesc='+cd+'&date='+s2+'&clientname='+client+'&startdate='+s+'&emailto='+email+'&emailcc='+emailcc;
		   //alert(link);
			window.open(link,'_blank');
	
	   }

	   

	   function ShowOutstandingReport()
	   {
	       var custidandemail = document.outst.custid.value.split('-');
		   
		   var c=custidandemail[0];
		   var email = custidandemail[1];
		   //var s=document.outst.startdate.value;
		   var custdesc=document.outst.custid.text;
		   //element.options[element.selectedIndex].text
		   var cd = document.outst.custid.options[document.outst.custid.selectedIndex].text;
		   //var s2= s.substring(6,10) + '-' + s.substring(3,5) + '-' + s.substring(0,2);
		   var s2='<?=date("d-m-Y")?>';
		   var client='Shree Communications';
		    var ccaddress='manish@shreecomm.com';
		   //alert(c);
		   //alert(s);
		   //alert(cd);
		   //clientname=ABC&custdesc=xyz&custid=195&date=11-21-2013
		   //alert('outprint_report.php?custid='+c+'&custdesc='+cd');
		   //window.location.href = 'outprint_report.php?custid='+c+'&custdesc='+cd; // +'&startdate=' +s2;
		   //window.location.href = 
		   var link = 'report_ledger.php?custid='+c+'&custdesc='+cd+'&date='+s2+'&clientname='+client+'&custemail='+email+'&emailcc='+ccaddress;
		   //alert(link);
		   //window.location.href = link;
		   window.open(link,'_blank');
	   }
              
	</script>
    
    
  <td>
      <label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;"> Outstanding Report</label></td>
  <div  ng-controller="outstanding">
    
     <div  align="center">
     <form name="outst" method="post" action="outstanding.php">
   <table  cellpadding="0" id="special"  cellspacing="0" border="0" width="966" bgcolor="#FFFFFF" >
 
 
 <tr>
       <td width="183" ><label style="text-align:left; font-size:14px;  font-weight:bold; vertical-align:middle;">From Date :</label></td>
        <td width="292" style="text-align:left; font-size:14px; font-weight:bold; vertical-align:middle;">
	    	<input type="text" name="startdate" id="startdate" value="<?=$sd?>" class="smallInput"/>
	   </td>
	</tr>
    <tr>
     <td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Customer/Dist Name :</label></td>					
    					
    <td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">						
    <select  name="custid" id="custid" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >						
        <option value="0">ALL</option>				
            <?						
            $sqlct="select * from customermast where status=0 order by custdesc";					
            $resct=mysql_query($sqlct);													
            while($rowct=mysql_fetch_assoc($resct))					
            {							
                $s='';							
                if($rowct['custid']==$_SESSION['custid'])								
                 $s='selected="selected"';									
                else									
                $s='';					
            ?>							
                <option  <?=$s?> value="<?=$rowct['custid'].'-'.$rowct['email']?>"><?=$rowct['custdesc']?></option>					
            <?							
                }						
            ?>							
    </select>					
    </td>					
    
        <td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Customer Type</label></td>					
            <td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>				
            <td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">						
          <select  name="custtype" id="custtype" class="smallInput" style="width:250px; font-size:12px; font-weight:bold;" >						
            <option value="0">ALL</option>						
            <?						
            $sqlb="select distinct custtype from customermast where status=0 order by custtype";						
            $resb=mysql_query($sqlb);						
            while($rowb=mysql_fetch_assoc($resb))					
            {							
                $s1='';								
                 if($rowb['custtype']==$_SESSION['custtype'])									
                    $s1='selected="selected"';									
                else								
                    $s1='';						
                ?>					
                    <option  <?=$s1?> value="<?=$rowb['custtype']?>"><?=$rowb['custtype']?></option>					
                <?							
            }						
            ?>							
    </select>					
         <!--   </td>				
            </tr> -->
			
          <tr>
             <td style="text-align:right; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">						
              <input type="button" name="OutstandingReport" value="Outstanding Report" class="btn btn-sm btn-inverse" onclick="ShowOutstandingReport()" >	
              </td>			
            
            <td style="text-align:right; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">    					
               <input type="button" name="Statement" value="Statement" class="btn btn-sm btn-primary" onclick="ShowStatement()" >    
            </td>    		
            
			 <td colspan="3" style="text-align:center; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">    					
               <input type="button" name="Invoice" value="Invoice" class="btn btn-sm btn-success" onclick="ShowInvoice()" >    
            </td> 
			
              <td style="text-align:right; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
    		    <td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;"></label></td>    				
	        <td colspan="4" style="text-align:right; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">			
                <input type="submit" name="submit" value="Search" class="btn btn-sm btn-info" >					
            </td>
            </tr>
        </table>		
    </form>		
            
         <div class="gridStyle1" ng-grid="gridOptions"></div>		
            </div>
            </div>
            </body>
            </html>